package com.jiangxfei.mymvp.app.home;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.jiangxfei.mymvp.R;
import com.jiangxfei.mymvp.app.home.adapter.RecyLoadAdapter;
import com.jiangxfei.mymvp.app.home.bean.User;
import com.jiangxfei.mymvp.app.home.module.HomeActivityModule;
import com.jiangxfei.mymvp.app.home.mvp.HomeConstract;
import com.jiangxfei.mymvp.app.home.mvp.HomePresenter;
import com.jiangxfei.mymvp.base.BaseActivity;
import com.jiangxfei.mymvp.base.BaseApplication;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * @author: JiangXFei
 * @date: 2018/1/8 0008
 * @content:
 */


public class HomeActivity extends BaseActivity<HomePresenter> implements HomeConstract.View {

    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.recy_show)
    RecyclerView recyShow;
    @Inject
    RecyLoadAdapter adapter;
    @Inject
    List<User> userList;
    @Inject
    GridLayoutManager gridLayoutManager;

    @Override
    public int initLayout(Bundle savedInstanceState) {
        return R.layout.activity_home;
    }

    @Override
    public void initData() {
        mActivity = this;
        mContext = this;
        BaseApplication.get(this)
                .getAppComponent()
                .addSub(new HomeActivityModule(this))
                .inject(this);
        initRecy();

    }

    private void initRecy() {
        recyShow.setLayoutManager(gridLayoutManager);
        recyShow.setAdapter(adapter);
        refreshLayout.setOnRefreshListener(refreshLayout -> {
            mPresenter.requestUser(true);
        });
        refreshLayout.setOnLoadMoreListener(refreshLayout -> {
            mPresenter.requestUser(false);
        });
    }


    @Override
    public void setData(Object o) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {
        refreshLayout.finishRefresh();//传入false表示刷新失败
        refreshLayout.finishLoadMore();//传入false表示加载失败
    }

    @Override
    public void message(String str) {

    }


    @Override
    public void loadOnSuccess(List<User> userList) {

    }

//    @Override
//    public void testOnSuccess(String str) {
//        Toast.makeText(mContext, str, Toast.LENGTH_SHORT).show();
//    }
////
//    @Override
//    public HomeConstract.TestParam getTestParam() {
//        return new HomeConstract.TestParam("POLYGON((120.390146 36.102752,120.390259 36.102736,120.390433 36.102737,120.390631 36.102764,120.390879 36.10282,120.391225 36.102844,120.391521 36.102839,120.391645 36.102827,120.391591 36.102503,120.391585 36.102169,120.391456 36.10206,120.390242 36.101998,120.390146 36.102752))",
//                "07",
//                "113",
//                "05_03");
//    }
//
//    @Override
//    public HomeConstract.LoginParam getLoginParam() {
//        return new HomeConstract.LoginParam("linkhead","linkhead");
//    }

}
